package com.atguigu.controller;

import com.atguigu.domain.CrmBanner;
import com.atguigu.service.CrmBannerService;
import com.atguigu.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;

    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable("page") String page,
                        @PathVariable("limit") String limit){
        Page<CrmBanner> bannerPage = new Page<>();
        crmBannerService.page(bannerPage,null);
        return R.ok().data("items",bannerPage.getRecords())
                .data("total",bannerPage.getTotal());
    }

    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return R.ok();
    }

    @GetMapping("get/{id}")
    public R get(@PathVariable String id){
        CrmBanner banner = crmBannerService.getById(id);
        return R.ok().data("item",banner);
    }

    @PutMapping("update")
    public R updateById(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }
}
